package api

import (
	"jmicro/app/jshop/api/internal/controller"
	v12 "jmicro/app/jshop/api/internal/controller/v1"
	"jmicro/app/pkg/options"
	"jmicro/jmicro/server/restserver"
	"jmicro/jmicro/server/restserver/middlewares"
)

func initRouter(api *restserver.Server, jwt *options.JwtOptions, usert v12.UsersStore) {
	v1 := api.Group("/v1")
	ugroup := v1.Group("/user")
	baseRouter := v1.Group("/base")

	// rpc的连接，基于服务发现
	//data, err := rpc.GetDataFactoryOr(cfg.Registry)
	//if err != nil {
	//	panic(err)
	//}
	//serviceFactory := service.NewService(data, cfg.Jwt, cfg.Sms)

	//用户相关的api
	uts := api.Translator()
	controller.Trans = uts
	{
		ugroup.POST("pwd_login", usert.Login)
		ugroup.POST("register", usert.Regisger)

		jwtAuth := newJWTAuth(jwt)
		//第三方登录模式 暂不用
		//jwtStragy:=jwtAuth.(auth.JWTStrategy)
		//jwtStragy.LoginHandler()
		ugroup.GET("detail", middlewares.TracingHandler(api.ServerName()), jwtAuth.AuthFunc(), usert.GetUserDetail)
		ugroup.GET("list", usert.List)
		ugroup.PATCH("update", jwtAuth.AuthFunc(), usert.UpdateUser)
	}
	//验证相关的api
	//smsCtl := sms2.NewSmsController(serviceFactory, api.Translator())
	{
		baseRouter.POST("send_sms", usert.SendSms)
		baseRouter.GET("captcha", usert.GetCaptcha)
	}
}
